package jrandom.algorithm.factory.random;

import java.util.Random;

import jrandom.algorithm.factory.ValueFactory;

public class RandomCharFactory extends ValueFactory {
	private char minValue;
	private char maxValue;

	public RandomCharFactory(int tcNum) {
		super(tcNum);
	}

	@Override
	public Object[] getValue(String min, String max) {
		String base = " 	!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'abcdefghijklmnopqrstuvwxyz{|}~";
		try {
			if (min.toCharArray().length == 1 && max.toCharArray().length == 1) {
				minValue = min.toCharArray()[0];
				maxValue = max.toCharArray()[0];
			} else {
				throw new Exception();
			}
		} catch (Exception e) {
			minValue = base.charAt(0);
			maxValue = base.charAt(base.length()-1);
		}

		Random random = new Random();  
		if (min == null || max == null || maxValue < minValue){
			for (int i = 0; i < values.length; i++) {
				int number = random.nextInt(base.length());
				values[i] = base.charAt(number);
			}
		} else if (base.indexOf(String.valueOf(minValue)) == -1 || base.indexOf(String.valueOf(maxValue)) == -1){
			for (int i = 0; i < values.length; i++) {
				int number = random.nextInt(base.length());
				values[i] = base.charAt(number);
			}
		} else {
			for (int i = 0; i < values.length; i++) {
				String subBase = base.substring(base.indexOf(String.valueOf(minValue)), base.indexOf(String.valueOf(maxValue))+1);
				int number = random.nextInt(subBase.length());
				values[i] = base.charAt(number);
			}
		}
		return values;
	}

	@Override
	public void addTC(Object newTC) {
		// TODO Auto-generated method stub

	}

	@Override
	public double[] getDistance(Object candi) {
		// TODO Auto-generated method stub
		return null;
	}

}

